package cn.cloud.all.security.core.userdetails.memory;

import cn.cloud.all.security.core.GrantedAuthority;
import cn.cloud.all.security.core.SimpleGrantedAuthority;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

public class UserAttribute {

    private List<GrantedAuthority> authorities = new Vector<>();
    private boolean enabled = true;
    private String password;

    public void addAuthority(GrantedAuthority newAuthority) {
        this.authorities.add(newAuthority);
    }

    public List<GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    public void setAuthorities(List<GrantedAuthority> authorities) {
        this.authorities = authorities;
    }

    public void setAuthoritiesAsString(List<String> authoritiesAsStrings) {
        this.authorities = new ArrayList<>(authoritiesAsStrings.size());
        for (String role : authoritiesAsStrings) {
			this.authorities.add(new SimpleGrantedAuthority(role));
        }
    }

    public String getPassword() {
        return password;
    }

    public boolean isEnabled() {
        return enabled;
    }

    public boolean isValid() {
        return (this.password != null) && (authorities.size() > 0);
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
